package com.gz.purchase.library.pojo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * author wanner1991
 */
public class PurchaseOrderInfo {
    private String ssn;//代购订单编号
    private double should_pay; //应付款
    private double real_pay; //实付款
    private String ssn_note;//备注
    private long create_at;//创建时间 unixtime
    private List<ProductInfo> products;

    public String getSsn() {
        return ssn;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public double getShould_pay() {
        return should_pay;
    }

    public void setShould_pay(double should_pay) {
        this.should_pay = should_pay;
    }

    public double getReal_pay() {
        return real_pay;
    }

    public void setReal_pay(double real_pay) {
        this.real_pay = real_pay;
    }

    public String getSsn_note() {
        return ssn_note;
    }

    public void setSsn_note(String ssn_note) {
        this.ssn_note = ssn_note;
    }

    public long getCreate_at() {
        return create_at;
    }

    public void setCreate_at(long create_at) {
        this.create_at = create_at;
    }

    public List<ProductInfo> getProducts() {
        return products;
    }

    public void setProducts(List<ProductInfo> products) {
        this.products = products;
    }

    public static List<PurchaseOrderInfo> parse(JSONArray jsonArray) throws JSONException {
        if (jsonArray == null || jsonArray.length() == 0){
            return null;
        }

        List<PurchaseOrderInfo> infos = new ArrayList<PurchaseOrderInfo>();
        PurchaseOrderInfo info = null;
        for (int i = 0 ; i < jsonArray.length() ; i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            info = new PurchaseOrderInfo();
            info.ssn = jsonObject.getString("ssn");
            info.should_pay = jsonObject.getDouble("should_pay");
            info.real_pay = jsonObject.getDouble("real_pay");
            info.ssn_note = jsonObject.getString("ssn_note");
            info.create_at = jsonObject.getLong("create_at");
            info.products = ProductInfo.parse2(jsonObject.getJSONArray("products"));

            infos.add(info);

        }

        return infos;
    }
}
